import { listProducer } from '@/apis/asset/common';
import { ref } from 'vue';

/** 厂商列表 */
export function producer(options?: { onSuccess?: () => void }) {

    const loading = ref(false)
    const producerList = ref([{}])

    const getProducerList = async (name?: string) => {
        try {
            loading.value = true
            const res = await listProducer({ name: name })
            const data = res.data;
            producerList.value = data.map(item => {
                return {
                    label: item.name,
                    value: item.id
                };
            });
            options?.onSuccess && options.onSuccess()
        }finally {
            loading.value = false
        }
    }
    return { producerList, getProducerList, loading }
}
